package com.itheima.HomeWork_day04;
/*
instanceof关键字:
处理多态中转型存在的风险
 */
public class InstanceofTest {

    public static void main(String[] args) {

        Bird b=new Eagle();
        b.eat();


        //在想在转型前进行类型验证,处理异常
        if (b instanceof Ostrich){
            Ostrich o=(Ostrich) b;
            o.eat();
            o.fly();
        }
    }
}

//bird类
abstract class Bird{
     abstract void eat();
}


//Ostrich类
class Ostrich extends Bird{

    void fly() {
        System.out.println("跑的最快,但飞不了");
    }

    @Override
    void eat() {
        System.out.println("吃小虫子");
    }
}

//Eagle类
class Eagle extends  Bird{
    @Override
    void eat() {
        System.out.println("吃小蛇");
    }
}